package com.tuanda.app.customviewdemo.cavans;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by LiDongduo on 2018/9/19.
 */
public class DrawPathView extends View {

    private Paint mPaint;
    private Path mPath;

    public DrawPathView(Context context) {
        this(context,null);
    }

    public DrawPathView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public DrawPathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(Color.RED);
        mPath = new Path();
        RectF leftRectF = new RectF(100,50,200,150);
        RectF rightRectF = new RectF(200,50,300,150);
        mPath.addArc(leftRectF,-225,225);
        mPath.arcTo(rightRectF,-180,225, false);
        mPath.lineTo(200,221);
        mPath.close();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(mPath,mPaint);
    }
}
